package com.fastloan.mgt.postloan.app;

import com.fastloan.mgt.postloan.enums.PostLoanEnums;
import com.fastloan.mgt.postloan.model.ZyPostLoanMonitor;
import com.fastloan.mgt.postloan.service.ZyPostLoanMonitorService;
import com.kawins.base.baseabs.BaseController;
import com.kawins.result.ResultEnum;
import com.kawins.result.ResultTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * Created by gelon on 2017/11/17.
 */
@RestController
@RequestMapping("/api/zy/postloan")
public class PostLoanAppController extends BaseController<ZyPostLoanMonitor> {

    @Autowired
    ZyPostLoanMonitorService postLoanMonitorService;


    /**
     * 保存一个手动的贷后
     */
    @PostMapping("/saveUpdatePostloan")
    public ResultTo saveUpdatePostloan(ZyPostLoanMonitor zyPostLoanMonitor) {
        zyPostLoanMonitor = postLoanMonitorService.saveUpdatePostloan(zyPostLoanMonitor);
        return new ResultTo().setData(zyPostLoanMonitor);
    }


    /**
     * 如果没有postloanId 则新建一个贷后   然后保存贷后文件   否则直接保存贷后文件
     */
    @PostMapping("/saveUpdatePostloanFile")
    public ResultTo saveUpdatePostloanFile(String appId, String postloanId, MultipartFile file) {
        ZyPostLoanMonitor postLoanMonitor = postLoanMonitorService.saveUpdatePostloanFile(appId, postloanId, file);
        if (postLoanMonitor != null) {
            return new ResultTo().setData(postLoanMonitor);
        }
        return new ResultTo(ResultEnum.OPERATION_FAILED);
    }

    /**
     * 获取贷后实施方式
     */
    @PostMapping("/implType")
    public ResultTo getImplType() {
        return new ResultTo().setData(PostLoanEnums.ImplementType.values());
    }

    /**
     * 获取贷后实时枚举
     */
    @PostMapping("/resultType")
    public ResultTo getResultType() {
        return new ResultTo().setData(PostLoanEnums.ImplementResult.values());
    }

}
